<?
require_once('sdk/src/facebook.php');

 $config = array(
    'appId' => '187884601256536',
    'secret' => '66319d9fff5d46a3eb7c0d7f092bafcf',   	
    'cookie' => true
  );
	  $facebook = new Facebook($config);
	  $user_id = $facebook->getUser();

echo $facebook->getAccessToken();

if(empty($user_id)) $user_id = $_REQUEST['user_id'];

	  
//echo $user_id;

	  if($user_id !=0)
	  {
	  	require_once("classes/index.class.php");
		$objUser = new User($user_id);
	  }
	  else 
	  {
	   $login_url = $facebook->getLoginUrl();
	    echo 'Please <a href="' . $login_url . '">login.</a>';
	  }		
	//	echo $user_id;

	$signed_request = $_POST['signed_request'];

	list($encoded_sig, $payload) = explode('.', $signed_request, 2); 

	    $data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);
	    $token=$data['oauth_token'];
//echo $token;

      
         // Show photo upload form to user and post to the Graph URL
         $graph_url= "https://graph.facebook.com/me/photos?"
         . "access_token=" .$token;

         echo '<html><body>';
         echo '<form enctype="multipart/form-data" action="'
         .$graph_url .' "method="POST">';
         echo 'Please choose a photo: ';
         echo '<input name="source" type="file"><br/><br/>';
         echo 'Say something about this photo: ';
         echo '<input name="message" 
             type="text" value=""><br/><br/>';
         echo '<input type="submit" value="Upload"/><br/>';
         echo '</form>';
         echo '</body></html>';

?>
